package com.linwen.excise.leetcode;

import java.util.Arrays;

/**
 * @ClassName _322零钱兑换
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/22 9:28 PM
 * @Version 1.0
 */
public class _322零钱兑换 {
    public static void main(String[] args) {
        int[] coins = {2,3,5};
        int amount = 11;
        System.out.println(coinChange(coins,amount));

    }

    public static int coinChange(int[] coins, int amount) {
        Arrays.sort(coins);
        int result = 0;
        for (int i = coins.length - 1; i >= 0; ) {
            if(amount>=coins[i]){
                amount = amount - coins[i];
                result++;
            }else {
                i--;
            }
        }
        if(amount>0){
            return -1;
        }
        return result;
    }
}
